#!/usr/bin/python
# -*- coding: UTF-8 -*-
# author : bird.zhang@ximalaya.com
# encoding=utf-8

import pandas as pd


def get_str(group):
    result = ''
    for x in group:
        result += (x + ' ')
    return result


# item行中有'\r'，通过指定'\n'来判断item分割
# df = pd.read_csv('tb_live_record_all.csv', index_col='id', lineterminator='\n')


df = pd.read_csv('result.csv', encoding='utf-8', index_col='id')

df = df[['uid', 'metadata_value']]

# print(df)

df.info()

grouped = df.groupby('uid')['metadata_value']

ret = grouped.apply(get_str)

# print type(grouped)

# ret = {}
#
# for x, y in grouped:
#     metadata_value_str = ''
#     for z in y:
#         metadata_value_str += (z + ' ')
#     ret[x] = metadata_value_str

# print(type(ret))

# print(ret)


ret.to_csv('tb_live_record_all.csv', encoding='utf-8')
